package com.xinzhi.controller;

import com.xinzhi.log.LoginLog;
import com.xinzhi.service.IAuthCodeLoginService;
import com.xinzhi.service.IVerifyService;
import com.xinzhi.service.IloggingStatusService;
import com.xinzhi.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {
    @Autowired
    private IAuthCodeLoginService authCodeLoginService;
    @Autowired
    private IVerifyService verifyService;
    @Autowired
    private IloggingStatusService loggingStatusService;
    @Autowired
    private LoginLog loginLog;


    /**
     * 验证码登录
     * @param phone 手机号
     * @param authCode 验证码
     * @return
     */
    @GetMapping("/authCodeLogin")
    public Result authCodeLogin (@RequestParam("phone") String phone,@RequestParam("authCode") String authCode){
        return authCodeLoginService.authCodeLogin(phone,authCode);
    }

    /**
     * 发送验证码
     * @param phone 手机号
     * @return
     */
    @GetMapping("/getAuthCode")
    public Result getAuthCode(String phone){
        return verifyService.getCode(phone);
    }

    /**
     * 验证验证码
     * @param authCode 验证码
     * @param phone 手机号
     * @return
     */
    @GetMapping("/isValid")
    public Result isValid(@RequestParam("authCode") String authCode,@RequestParam("phone") String phone){
        return verifyService.iVAuthCode(authCode,phone);
    }

    /**
     * 获取登录状态
     * @param phone 手机号
     * @return
     */
    @GetMapping("/loggingStatus")
    public Result loggingStatus(String phone){
        return loggingStatusService.getLoggingStatus(phone);
    }

    /**
     * 获取登录时间
     * @param id 用户id
     * @return
     */
    @GetMapping("/loginTime")
    public void loginTime(Integer id){
        loginLog.insertLoginLog(id,2);
    }

    /**
     * 删除redis状态
     * @param phone
     * @return
     */
    @GetMapping("/deleteRedis")
    public Result deleteRedis(String phone){
        return loggingStatusService.deleteRedis(phone);
    }

}
